package obj;

import game.GameWin;
import utils.GameUtils;

import java.awt.*;

public class BossObj extends GameObj {
    //初始血量值
    public static final int initLife = 100;
    //血量
    int life = 10;
    int life = initLife;
    //护盾,受到伤害量=初始伤害量-护盾值
    int shield = 0;

    public BossObj(Image image, int x, int y, int width, int height, double speed, GameWin frame) {
        super(image, x, y, width, height, speed, frame);
    }


        public int getLife() {
        return life;
    }

    public int getInitLife() {
        return initLife;
    }


    @Override
   public void paintSelf(Graphics gImage) {
        super.paintSelf(gImage);
        if (x > 550 || x < -50) {
        if (x > 500 || x < 0) {
            speed = -speed;
        }
        x += speed;
        //BOSS随血量变化会有三种移动速度和护盾值
        if (life > (initLife / 2)) {
            x += speed;
        } else if (life > (initLife / 4)) {
            //加速移动和护盾提高
            double quick = speed * 2;
            x += quick;
            this.shield = 2;
        } else {
            //加速移动和护盾提高
            double quick = speed * 3;
            x += quick;
            this.shield = 4;
        }

        for (ShellObj shellObj : GameUtils.shellObjList) {
            if (this.getRec().intersects(shellObj.getRec())) {
                shellObj.setX(-100);
                shellObj.setY(100);
                GameUtils.removeList.add(shellObj);
                life--;
                life -= (5 - this.shield);
            }
            if (life <= 0) {
                GameWin.state = 4;
@@ -36,11 +63,11 @@ public class BossObj extends GameObj {
        gImage.fillRect(20, 40, 100, 10);
        //血条的绘制
        gImage.setColor(Color.red);
        gImage.fillRect(20, 40, life * 100 / 10, 10);
        gImage.fillRect(20, 40, life, 10);
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
